package com.bobi.tfca.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bobi.tfca.model.entity.ActivityEntity;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 文章持久层
 * @author 李文发
 * @date 2024/4/3
 */
@Mapper
public interface ActivityDao extends BaseMapper<ActivityEntity> {

    @Select("SELECT activity.activity_id, activity_name, activity_details, sign_condition, sign_start_time, sign_end_time, act_start_time, act_end_time, outside_picture, activity_status, limited_num, activity_place, publish_time, group_id FROM activity, act_mem" +
            " WHERE act_mem.activity_id = activity.activity_id AND act_mem.member_id = #{memberId}")
    List<ActivityEntity> selAllJoinActivities(@Param("memberId") Integer memberId);

    @Update("UPDATE activity SET signed_num = signed_num + 1 WHERE signed_num + 1 <= activity.limited_num AND activity_id = #{activityId}")
    Boolean signup(@Param("activityId") Integer activityId);
}
